# Maintainer: Morten Linderud <foxboron@archlinux.org>
# Contributor: Maikel Wever <maikelwever@gmail.com>

pkgname=python-ldap
pkgver=3.4.3
pkgrel=3
pkgdesc="LDAP client API for Python"
url="https://python-ldap.readthedocs.io/"
arch=('loong64' 'x86_64')
license=('MIT')
depends=('python-pyasn1' 'python-pyasn1-modules' 'libldap')
makedepends=('python-setuptools' 'python-coverage')
checkdepends=('openldap' 'python-pyasn1' 'python-pyasn1-modules')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/python-ldap/python-ldap/archive/${pkgname}-${pkgver}.tar.gz")
sha256sums=('0f59a692a4761f70aff6629125a2574dd12f6660316bbac211325fed7a898f48')

prepare() {
  cd "$pkgbase-$pkgbase-$pkgver"

  # slapd fails to start because -F points to a non-empty directory.
  # Simply don't pass both -f and -F to slapd, it is only done when
  # converting slapd.conf to LDIF and pointless here.
  sed -i "/'-F', self.testrundir,/d" Lib/slapdtest/_slapdtest.py
}

build(){
  cd "$pkgbase-$pkgbase-$pkgver"
  python setup.py build
}

check(){
  cd "$pkgbase-$pkgbase-$pkgver"
  python -m unittest discover -vs Tests
}

package() {
  cd "$pkgbase-$pkgbase-$pkgver"
  python setup.py install --root="$pkgdir/" --optimize=1 --skip-build
  install -Dm 644 LICENCE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
